<?php
class RoleUserModel extends BaseModel {
    /**
     * Get user role information
     *
     * @param
     *            $uid
     * @return Array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getUserRloe($uid) {
        $map = array ();
        $map ['user_id'] = $uid;
        $roles = $this->where ( $map )->select ();
        $RoleModel = M ( 'Role' );
        foreach ( $roles as $key => $role ) {
            $r = $RoleModel->find ( $role ['role_id'] );
            $roles [$key] ['role_name'] = $r ['name'];
            $roles [$key] ['role_remark'] = $r ['remark'];
        }
        return $roles;
    }
    
    public function setUserRloe($uid, $role) {
        $rs = $this->query ( 'DELETE FROM `m_role_user` WHERE ( user_id = ' . $uid . ' )' );
        $rs = $this->query ( 'DELETE FROM `m_per` WHERE ( uid = ' . $uid . ' )' );
        $data ['user_id'] = $uid;
        $data ['role_id'] = $role;
        $this->add ( $data );
    }
}